﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GoDive.Contract
{

    public enum OperationStatus
    {
        Success,
        Error
    }

    public class ResponseStatusContract
    {
        public static string USERNOTEXITS = "该用户不存在！";

        public string Status { get; set; }

        public OperationStatus StatusCode { get; set; }

        public string Msg { get; set; }

        public dynamic Data { get; set; }


        public static ResponseStatusContract GenRequestErrorResponse(string msg)
        {
            return new ResponseStatusContract { Status = "Error", StatusCode = OperationStatus.Error, Msg = msg };
        }

        public static ResponseStatusContract GenRequestErrorResponse()
        {
            return new ResponseStatusContract { Status = "Error", StatusCode = OperationStatus.Error, Msg = "请检查传入的参数是否正确！" };
        }

        public static ResponseStatusContract GenServiceErrorResponse()
        {
            return new ResponseStatusContract { Status = "Error", StatusCode = OperationStatus.Error, Msg = "服务端接口出现意外错误！" };
        }

        public static ResponseStatusContract GenServiceErrorResponse(string msg)
        {
            return new ResponseStatusContract { Status = "Error", StatusCode = OperationStatus.Error, Msg = "服务端接口出现意外错误！错误信息：" + msg + "" };
        }

        public static ResponseStatusContract GenServiceErrorResponse(Exception ex)
        {
            string msg = string.Empty;
            if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
            {
                msg = ex.InnerException.Message;
            }
            else
            {
                msg = ex.Message;
            }
            return new ResponseStatusContract { Status = "Error", StatusCode = OperationStatus.Error, Msg = "服务端接口出现意外错误！错误信息：" + msg + "" };
        }

        public static ResponseStatusContract GenSuccessResponse()
        {
            return new ResponseStatusContract { Status = "Success", StatusCode = OperationStatus.Success, Msg = "操作成功！" };
        }

        public static ResponseStatusContract GenSuccessResponse(dynamic data)
        {
            return new ResponseStatusContract { Status = "Success", StatusCode = OperationStatus.Success, Msg = "操作成功！", Data = data };
        }

    }
}
